home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / git-4.3 / git-4 / git-4.3.11 / src / signals.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  2.6 KB  |  139 lines

  1. /* signal.c -- A file which should cantain some *REAL* signals management.  */
  2.  
  3. /* Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. /* Written by Tudor Hulubei and Andrei Pitis.  */
  20.  
  21.  
  22. #ifdef HAVE_CONFIG_H
  23. #include <config.h>
  24. #endif
  25.  
  26. #include <stdio.h>
  27.  
  28. #ifdef HAVE_STDLIB_H
  29. #include <stdlib.h>
  30. #else /* !HAVE_STDLIB_H */
  31. #include "ansi_stdlib.h"
  32. #endif /* !HAVE_STDLIB_H */
  33.  
  34. #include <signal.h>
  35.  
  36. #include "signals.h"
  37. #include "inputline.h"
  38. #include "tty.h"
  39. #include "misc.h"
  40.  
  41.  
  42. extern pid_t pid;
  43. extern char *screen;
  44. extern input_line_t *input;
  45.  
  46.  
  47. int suspend_allowed = OFF;
  48. int signals_status;
  49. int UserHeartAttack = 0;
  50.  
  51.  
  52. #ifdef SIGSTOP
  53.  
  54. RETSIGTYPE
  55. suspend(signum)
  56.     int signum;
  57. {
  58.     signal(signum, suspend);
  59.  
  60.     if (suspend_allowed)
  61.     {
  62.     tty_set_mode(TTY_CANONIC);
  63.     tty_defaults();
  64.     tty_put_screen(screen);
  65.     kill(pid, SIGSTOP);
  66.     }
  67. }
  68.  
  69. #endif
  70.  
  71.  
  72. RETSIGTYPE
  73. resume(signum)
  74.     int signum;
  75. {
  76.     extern int current_mode;
  77.     extern void refresh_after_suspend PROTO ((int));
  78.  
  79.     signal(signum, resume);
  80.  
  81.     refresh_after_suspend(current_mode);
  82. }
  83.  
  84.  
  85. RETSIGTYPE
  86. user_panic(signum)
  87.     int signum;
  88. {
  89.     signal(signum, user_panic);
  90.  
  91.     UserHeartAttack = 1;
  92. }
  93.  
  94.  
  95. void
  96. signals_dfl()
  97. {
  98.     signal(SIGTERM, SIG_DFL);
  99.     signal(SIGQUIT, SIG_DFL);
  100.     signal(SIGINT , SIG_DFL);
  101. }
  102.  
  103.  
  104. void
  105. signals(status)
  106.     int status;
  107. {
  108.     signals_status = status;
  109.     signal(SIGTERM, status == ON ? fatal_signal : SIG_IGN);
  110.     signal(SIGQUIT, status == ON ? fatal_signal : SIG_IGN);
  111.     signal(SIGINT , status == ON ? user_panic   : SIG_IGN);
  112. }
  113.  
  114.  
  115. void
  116. ignore_signals()
  117. {
  118.     signal(SIGILL,  SIG_IGN);
  119.     signal(SIGTRAP, SIG_IGN);
  120.     signal(SIGABRT, SIG_IGN);
  121.     signal(SIGUSR1, SIG_IGN);
  122.     signal(SIGUSR2, SIG_IGN);
  123.     signal(SIGPIPE, SIG_IGN);
  124.     signal(SIGFPE,  SIG_IGN);
  125. }
  126.  
  127.  
  128. void
  129. restore_signals()
  130. {
  131.     signal(SIGILL,  SIG_DFL);
  132.     signal(SIGTRAP, SIG_DFL);
  133.     signal(SIGABRT, SIG_DFL);
  134.     signal(SIGUSR1, SIG_DFL);
  135.     signal(SIGUSR2, SIG_DFL);
  136.     signal(SIGPIPE, SIG_DFL);
  137.     signal(SIGFPE,  SIG_DFL);
  138. }
  139.